package com.xhwl.logistics.service.logistics.impl;

import com.alibaba.fastjson.JSON;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.xhwl.common.pojo.ResultJson;
import com.xhwl.logistics.dao.mapper.logistics.DeviceMapper;
import com.xhwl.logistics.entity.logistics.Device;
import com.xhwl.logistics.query.iot.IotDeviceQuery;
import com.xhwl.logistics.service.cent.iot.ICentDeviceCoreService;
import com.xhwl.logistics.service.logistics.DeviceService;
import com.xhwl.logistics.util.PageResult;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author lin.yang
 * @since 2023-12-15
 */
@Service
@Slf4j
public class DeviceServiceImpl extends ServiceImpl<DeviceMapper, Device> implements DeviceService {
    /**
     * 设备服务
     */
    @Autowired
    ICentDeviceCoreService deviceCoreService;

    @Override
    public ResultJson<PageResult<Device>> pageDevice(IotDeviceQuery query) {
        log.info("pageDevice() called with parameters => 【query = {}】",JSON.toJSON(query));
        return deviceCoreService.listDevice(query);

       /* DevicePageQuery devicePageQuery = new DevicePageQuery();
        //分页数据信息
        devicePageQuery.setSize(query.getSize());
        devicePageQuery.setCurrent(query.getCurrent());
        //2:代表视频类的点位设备信息类型，如果为空需要进行默认设置
        if (ObjectUtil.isNull(query.getDeviceTypeId())&&ObjectUtil.isEmpty(query.getDeviceTypeId())) {
            //如果为空则取设备类型为2代表为视频设备类型的点位信息
            devicePageQuery.setDeviceTypeId(2);
        }
        //设备名称或者详情位置
        if (ObjectUtil.isNotNull(query.getDeviceNameOrDetailPostionName())) {
            devicePageQuery.setDetailPositionOrName(query.getDeviceNameOrDetailPostionName());
        }
        //产品id
        if (ObjectUtil.isNotNull(query.getProductId())&&ObjectUtil.isNotEmpty(query.getProductId())) {
            devicePageQuery.setProductId(query.getProductId());
        }
        //项目id
        if (ObjectUtil.isNotNull(query.getProjectId())&&ObjectUtil.isNotEmpty(query.getProjectId())) {
            devicePageQuery.setProjectId(query.getProjectId());
        }
*/
        //获取分页数据信息
      /*  Page<DeviceDTO> deviceDTOPage = deviceService.listPageDevice(query.getIndustryId().shortValue(), devicePageQuery);
        List<DeviceDTO> deviceDTOS = Optional.ofNullable(deviceDTOPage).map(x -> x.getRecords()).orElse(Collections.emptyList());
        List<Device>resultDevice=new ArrayList<>();
        if (deviceDTOS.size()>0) {
            for (DeviceDTO deviceDTO : deviceDTOS) {
                Device device = new Device();
                //设备名称
                device.setDeviceName(deviceDTO.getName());
                device.setId(deviceDTO.getId());
                device.setProjectId(deviceDTO.getProjectId());
                //设备项目名称
                device.setProjectName(deviceDTO.getProjectName());
                //device.setAccessProtocol(deviceDTO.getpro);
                //设备详细位置
                device.setDeviceDetailPosition(deviceDTO.getDetailPosition());
                resultDevice.add(device);
            }
        }
        Page<Device>resultPage=new Page<>();
        resultPage.setCurrent(deviceDTOPage.getCurrent());
        resultPage.setSize(deviceDTOPage.getSize());
        resultPage.setRecords(resultDevice);
        log.info("获取到的设备分页信息{}", JSON.toJSON(resultPage));
        return ResultJson.success(PageResultUtils.getPageResult(resultPage, resultPage.getRecords()));*/
    }
}
